package filenavigation

import (
	"gitlab.local/DO-module/new-filemanage-module/src/core/fileoperate"
	"gitlab.local/DO-module/new-filemanage-module/src/core/middleware"
	//"gitlab.local/TerraMaster/tos-modules/core/acl"
	"gitlab.local/TerraMaster/tos-modules/core/acl"
	//"gitlab.local/TerraMaster/tos-modules/middleware"

	"gitlab.local/DO-module/new-filemanage-module/src/core/network"
	"gitlab.local/DO-module/new-filemanage-module/src/core/nginx"
	"gitlab.local/DO-module/new-filemanage-module/src/service/file_collect"
	"gitlab.local/DO-module/new-filemanage-module/src/service/file_recently"
	"gitlab.local/DO-module/new-filemanage-module/src/service/file_safeBox"
	"gitlab.local/DO-module/new-filemanage-module/src/service/file_share"
	"gitlab.local/TerraMaster/tos-modules/database"
	//"gitlab.local/TerraMaster/tos-modules/network"
	//"gitlab.local/TerraMaster/tos-modules/nginx"
	"gitlab.local/DO-module/new-filemanage-module/src/core/tnasonline"
	//"gitlab.local/TerraMaster/tos-modules/tnasonline"
	"io"
	"os"
)

type FileSystem string

const (
	SMB    FileSystem = "cifs"
	NFS    FileSystem = "nfs"
	Volume            = "volume"
	Usb               = "usb"
	Mount             = "mount"
)

type FileNav struct {
	navigation Navigation
	dbGetter   database.DbGetter
	fOptGetter fileoperate.Getter
	aclService acl.FolderAttrService
}

type Remoter struct {
	ID              string     `json:"id"`
	SourcePath      string     `json:"source_path"`
	DestinationPath string     `json:"destination_path"`
	Protocol        string     `json:"transport_protocol"`
	TaskName        string     `json:"task_name"`
	Version         string     `json:"version,omitempty"`
	Username        string     `json:"username,omitempty"`
	Password        string     `json:"password,omitempty"`
	OnBoot          int        `json:"power_boot"`
	FileSystem      FileSystem `json:"fs"`
	// 记录创建时间，仅仅是后端用到此字段，因为gin框架返回结果里面的列表总是无序的，需要后端自行排序
	CreateTime string `json:"create_time"` // 例： 202205241842，方便string直接对比值
}

// 导航栏
type Navigation struct {
	Location     []Location
	collect      *file_collect.Collect
	Recently     *file_recently.Recently
	share        *file_share.Share
	safeBox      *file_safeBox.SafeBox
	recentlyFunc func(string, string) //文件复制或移动后，更新最近使用记录
}

// 位置
type Location struct {
	Name       string `json:"name"`        //名称
	Path       string `json:"path"`        //路径
	Volume     string `json:"volume"`      //卷
	VolumePath string `json:"volume_path"` //卷+路径
	FType      string `json:"f_type"`      //文件系统类型
	Type       string `json:"type"`        //目录类型
	CreateTime string `json:"create_time"` //创建时间
}

type collectListData struct {
	os.FileInfo
	path string
}
type HttpFile interface {
	Filename() string
	Open() (io.ReadCloser, error)
}

func New(db database.DbGetter,
	fOptGetter fileoperate.Getter,
	aclService acl.FolderAttrService,
	ng nginx.PortGetter,
	net network.Networkset,
	tnasOnline tnasonline.Ctl,
	m middleware.AuthChecker,
) *FileNav {
	return &FileNav{
		dbGetter:   db,
		fOptGetter: fOptGetter,
		aclService: aclService,
		navigation: Navigation{
			Location: []Location{},
			collect:  file_collect.New(),
			Recently: file_recently.New(db),
			share:    file_share.New(db, ng, net, tnasOnline),
			safeBox:  file_safeBox.New(m),
		},
	}
}
